const arr = [2,5,1,6,7,0,8]

// 时间复杂度 O(nlog n)
function quickSort(arr) {
    const n = arr.length;
    if (n < 2) return arr;
    const middle = arr[n-1];
    let left = arr.filter((num,index) => (num<=middle && index!==n-1)); 
    let right = arr.filter((num) => num>middle);
    return [...quickSort(left),middle,...quickSort(right)];
}

console.log(quickSort(arr))